﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace AutoTweet.Utilities
{
    public class Twitter
    {
        public static bool VerifyAccount(string username, string password)
        {
            bool result = false;
            try
            {
                string user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://twitter.com/account/verify_credentials.xml");
                request.Method = "GET";
                request.ContentType = "application/x-www-form-urlencoded";
                request.Headers.Add("Authorization", "Basic " + user);

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                result = response.StatusCode == HttpStatusCode.OK;
            }
            catch (Exception ex)
            {
                Logger.Log("Twitter::VerifyAccount", ex);
            }

            return result;
        }
    }
}
